package com.dk.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dk.mapper.TbUserMapper;
import com.dk.pojo.TbUser;
import com.dk.service.TbUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TbUserServiceImpl implements TbUserService {
    @Autowired
    private TbUserMapper userMapper;

    @Override
    public TbUser selectByUsername(String username) {
        LambdaQueryWrapper<TbUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        /*java8新特性 方法的引用*/
        LambdaQueryWrapper<TbUser> eq = lambdaQueryWrapper.eq(!StringUtils.isEmpty(username), TbUser::getUsername, username);
        TbUser tbUser = userMapper.selectOne(eq);
        return tbUser;
    }

    @Override
    public void addUser(TbUser user) {
        userMapper.insert(user);
    }

    @Override
    public void updateByName(TbUser tbUser) {
        userMapper.updateById(tbUser);
    }
}
